import Vue from "vue";
import Router from "vue-router";

Vue.use(Router);

/* Layout */
import Layout from "@/layout";

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: "/login",
    component: () => import("@/views/login/index"),
    hidden: true
  },
  {
    path: "/",
    component: Layout,
    redirect: "/dashboard",
    children: [
      {
        path: "dashboard",
        name: "Dashboard",
        component: () => import("@/views/dashboard/index"),
        meta: { title: "统计分析", icon: "el-icon-info" }
      }
    ]
  },


  {
    path: "/zijin",
    component: Layout,
    redirect: "/zijin/index",
    name: "Zijin",
    meta: { title: "资金管理", icon: "el-icon-info" },
  },

  {
    path: "/example",
    component: Layout,
    redirect: "/example/table",
    name: "Example",
    meta: { title: "商城管理", icon: "el-icon-s-help" },
    children: [
      {
        path: "table",
        name: "Table",
        component: () => import("@/views/table/index"),
        meta: { title: "商品管理", icon: "table" }
      },
      // {
      //  path:"addshop",
      //  name:"Addshop",
      //  hidden: true,
      //  component: () => import("@/views/table/addshop/index"),
      //  meta: { title: "新建商品", icon: "table", activeMenu: '/example/table' },
      //  },
       {
        path:"editshop",
        name:"Editshop",
        hidden: true,
        component: () => import("@/views/table/editshop/index"),
        meta: { title: "编辑商品", icon: "table", activeMenu: '/example/table' },
        },
      {
        path: "tree",
        name: "Tree",
        component: () => import("@/views/tree/index"),
        meta: { title: "配送费设置", icon: "tree" }
      },
      {
        path:"addpsf",
        name:"Addpsf",
        hidden: true,
        component: () => import("@/views/tree/addpsf/index"),
        meta: { title: "新增配送费模板", icon: "tree", activeMenu: '/example/tree' },
        },

    ]
  },

  {
    path: "/nested",
    component: Layout,
    redirect: "/nested/menu1",
    name: "Nested",
    meta: {title: "仓储管理",icon: "el-icon-info"},
    children: [
      {
        path: "menu1",
        component: () => import("@/views/nested/menu1/index"), // Parent router-view
        name: "Menu1",
        meta: { title: "总仓管理", role: [1] },
      },
      {
        path:"zongcangkucun",
        name:"Zongcangkucun",
        hidden: true,
        component: () => import("@/views/nested/menu1/zongcangkucun/index"),
        meta: { title: "总仓库存", icon: "zongcangkucun", activeMenu: '/nested/menu1' },
        },
        {
          path:"orderdetail2",
          name:"Orderdetail2",
          hidden: true,
          component: () => import("@/views/nested/menu1/orderdetail2/index"),
          meta: { title: "订单详情", icon: "orderdetail", activeMenu: '/nested/menu1' },
          },
      {
        path: "menu2",
        component: () => import("@/views/nested/menu2/index"),
        name: "Menu2",
        meta: { title: "区仓管理", role: [1,2] }
      },
      {
        path:"qucangkucun",
        name:"Qucangkucun",
        hidden: true,
        component: () => import("@/views/nested/menu2/qucangkucun/index"),
        meta: { title: "区仓库存", icon: "qucangkucun", activeMenu: '/nested/menu2' },
        },
        {
          path:"orderdetail",
          name:"Orderdetail",
          hidden: true,
          component: () => import("@/views/nested/menu2/orderdetail/index"),
          meta: { title: "订单详情", icon: "orderdetail", activeMenu: '/nested/menu2' },
          },
      {
        path: "menu3",
        component: () => import("@/views/nested/menu3/index"),
        name: "Menu3",
        meta: { title: "网点管理", role: [1,2,3] }
      },
      {
        path:"wangdiankucun",
        name:"Wangdiankucun",
        hidden: true,
        component: () => import("@/views/nested/menu3/wangdiankucun/index"),
        meta: { title: "网点库存", icon: "wangdiankucun", activeMenu: '/nested/menu3' },
        },
        {
          path:"orderdetail3",
          name:"Orderdetail3",
          hidden: true,
          component: () => import("@/views/nested/menu3/orderdetail3/index"),
          meta: { title: "订单详情", icon: "orderdetail", activeMenu: '/nested/menu3' },
          },
    ]
  },

  // {
  //   path: "/form",
  //   component: Layout,
  //   children: [
  //     {
  //       path: "index",
  //       name: "Form",
  //       component: () => import("@/views/form/index"),
  //       meta: { title: "支付管理", icon: "el-icon-info" }
  //     }
  //   ]
  // },

  {
    path: "/tongzhuangshui",
    component: Layout,
    redirect: "/tongzhuangshui/yatongguanli",
    name: "Tongzhuangshui",
    meta: {title: "桶装水管理",icon: "el-icon-info"},
    children: [
      {
        path: "yatongguanli",
        name: "Yatongguanli",
        component: () => import("@/views/tongzhuangshui/yatongguanli/index"),
        meta: { title: "押桶管理"}
      },
      {
        path: "tongjimingxi",
        name: "Tongjimingxi",
        hidden: true,
        component: () => import("@/views/tongzhuangshui/yatongguanli/tongjimingxi/index"),
        meta: { title: "统计明细"}
      },
      {
        path: "yatongmingxi",
        name: "Yatongmingxi",
        hidden: true,
        component: () => import("@/views/tongzhuangshui/yatongguanli/yatongmingxi/index"),
        meta: { title: "押桶明细"}
      },
      {
        path: "saledetail",
        name: "Saledetail",
        hidden: true,
        component: () => import("@/views/tongzhuangshui/yatongguanli/saledetail/index"),
        meta: { title: "销售订单详情"}
      },
      {
        path: "servicedetail",
        name: "Servicedetail",
        hidden: true,
        component: () => import("@/views/tongzhuangshui/yatongguanli/servicedetail/index"),
        meta: { title: "服务订单详情"}
      },
      {
        path: "yajinlishi",
        name: "Yajinlishi",
        hidden: true,
        component: () => import("@/views/tongzhuangshui/yatongguanli/yajinlishi/index"),
        meta: { title: "押金标准历史"}
      },
      {
        path: "edityjt",
        name: "Edityjt",
        hidden: true,
        component: () => import("@/views/tongzhuangshui/yatongguanli/edityjt/index"),
        meta: { title: "押金条备注"}
      },
      // 水票管理
      {
        path: "shuipiaoguanli",
        name: "Shuipiaoguanli",
        component: () => import("@/views/tongzhuangshui/shuipiaoguanli/index"),
        meta: { title: "水票管理"}
      },
      {
        path: "shuipiaomingxi",
        name: "Shuipiaomingxi",
        hidden: true,
        component: () => import("@/views/tongzhuangshui/shuipiaoguanli/shuipiaomingxi/index"),
        meta: { title: "水票明细"}
      },
      {
        path: "addshuipiao",
        name: "Addshuipiao",
        hidden: true,
        component: () => import("@/views/tongzhuangshui/shuipiaoguanli/addshuipiao/index"),
        meta: { title: "新建水票"}
      },
      {
        path: "editshuipiao",
        name: "Editshuipiao",
        hidden: true,
        component: () => import("@/views/tongzhuangshui/shuipiaoguanli/editshuipiao/index"),
        meta: { title: "编辑水票"}
      },
      {
        path: "shuipiaodetail",
        name: "Shuipiaodetail",
        hidden: true,
        component: () => import("@/views/tongzhuangshui/shuipiaoguanli/shuipiaodetail/index"),
        meta: { title: "水票详情"}
      },
    ]
  },
  {
    path: "/yingxiao",
    component: Layout,
    redirect: "/yingxiao/yingxiao",
    name: "yingxiao",
    meta: { title: "营销管理", icon: "el-icon-s-help" },
  },
  // {
  //   path: "/dingdan",
  //   component: Layout,
  //   redirect: "/dingdan/dingdan",
  //   name: "dingdan",
  //   meta: { title: "订单管理", icon: "el-icon-s-help" },
  // },
  {
    path: "/dingdan",
    component: Layout,
    children: [
      {
        path: "dingdan",
        name: "Dingdan",
        component: () => import("@/views/dingdan/index"),
        meta: { title: "订单管理", icon: "el-icon-info" }
      },
      {
        path: "detail",
        name: "Detail",
        hidden: true,
        component: () => import("@/views/dingdan/detail/index"),
        meta: { title: "销售订单详情", icon: "el-icon-info" }
      }
    ]
  },
  {
    path: "/kehu",
    component: Layout,
    redirect: "/kehu/kehu",
    name: "kehu",
    meta: { title: "客户管理", icon: "el-icon-s-help" },
  },
  {
    path: "/houtai",
    component: Layout,
    redirect: "/houtai/houtai",
    name: "houtai",
    meta: { title: "后台管理", icon: "el-icon-s-help" },
  },

  // {
  //   path: "/dingdan",
  //   component: Layout,
  //   children: [
  //     {
  //       path: "dingdan",
  //       name: "Dingdan",
  //       component: () => import("@/views/dingdan/index"),
  //       meta: { title: "订单管理", icon: "el-icon-info" }
  //     },
  //     {
  //       path: "detail",
  //       name: "Detail",
  //       hidden: true,
  //       component: () => import("@/views/dingdan/detail/index"),
  //       meta: { title: "销售订单详情", icon: "el-icon-info" }
  //     }
  //   ]
  // },

  {
    path: "/form",
    component: Layout,
       children: [
      {
        path: "form",
        name: "Form",
        component: () => import("@/views/form/index"),
        meta: { title: "配送员管理", icon: "el-icon-info" }
      }
    ]
  },


  {
    path: "/404",
    component: () => import("@/views/404"),
    hidden: true
  },
  // 404 page must be placed at the end !!!
  { path: "*", redirect: "/404", hidden: true }
];

const createRouter = () =>
  new Router({
    mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
  });

const router = createRouter();

export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher; // reset router
}

export default router;
